"""
可重入锁，是线程相关的锁。线程A获得可重复锁，并且可以多次成功获取，不会阻塞。最后要在线程A中做和acquire次数相同的release。
"""

import threading

# 主进程中使用
lock = threading.RLock()

ret = lock.acquire()
print(ret)

ret = lock.acquire()
print(ret)

lock.release()
lock.release()

# 线程中使用
def do(lock: threading.RLock):
    lock.acquire()
    print('do')
    lock.release()


threading.Thread(target=do, args=(lock,)).start()